#define _CRT_SECURE_NO_WARNINGS 1

//https://leetcode.cn/problems/last-stone-weight/description/


class Solution {
public:
    int lastStoneWeight(vector<int>& stones) {
        priority_queue<int> heap(stones.begin(), stones.end());

        while (heap.size() > 1)
        {
            int y = heap.top();
            heap.pop();
            int x = heap.top();
            heap.pop();
            if (x == y) continue;
            else
            {
                heap.push(y - x);
            }
        }

        if (heap.size() == 1) return heap.top();
        return 0;

    }
};